import { HTTP } from '../utils/http-p.js'
class KeywordModel extends HTTP{
	key='q'
	maxLength=10
	getHistory(){
		let words=JSON.parse(localStorage.getItem(this.key))
		if(!words){
			return []
		}
		return words
	}
	getHot(){
		return this.request({
			url:`book/hot_keyword`
		})
	}
	addToHistory(keyword){
		let words=this.getHistory()
		let has=words.includes(keyword)
		if(!has){
			let length=words.length
			if(length>=this.maxLength){
				words.pop()
			}
			words.unshift(keyword)
			localStorage.setItem(this.key,JSON.stringify(words))
		}
	}
//localStorage存取 要用JSON.stringify(val)和JSON.parse(data)
}
export {KeywordModel}